package com.guobox.movies.view.mview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

import com.guobox.movies.entity.BgColors;
import com.guobox.movies.utils.MetricsScreen;


/**
 * Created by xxl on 16/6/24.
 */
public class BgView extends RelativeLayout {

    private String mainColor,color1,color2,color3,color4;
    Paint paint;

    public BgView(Context context) {
        super(context);
        paint = new Paint();
    }

    public BgView(Context context, AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
    }

    public BgView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        paint = new Paint();
    }

    public BgView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        paint = new Paint();
    }

    public void setColos(BgColors bgColors){
        this.mainColor = bgColors.getColors()[0];
        this.color1 = bgColors.getColors()[1];
        this.color2 = bgColors.getColors()[2];
        this.color3 = bgColors.getColors()[3];
        this.color4 = bgColors.getColors()[4];
        invalidate();
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (mainColor == null) {
            return;
        }
        paint.setColor(MetricsScreen.string2int(mainColor));
        canvas.drawColor(paint.getColor());


        // TODO: 16/9/20 下面的是应用的
        int[] colors4 = {MetricsScreen.string2int(color4),
                Color.argb(00, 00, 00, 00)};

        int[] colors3 = {MetricsScreen.string2int(color3),
                Color.argb(00, 00, 00, 00)};
        int[] colors2 = {MetricsScreen.string2int(color2),
                Color.argb(00, 00, 00, 00)};
        int[] colors1 = {
                MetricsScreen.string2int(color1),
                Color.argb(00, 00, 00, 00)};
        RadialGradient radialGradient1 = new RadialGradient(1920,0,1100,colors1,null, Shader.TileMode.CLAMP);
        Paint paint1 = new Paint();
        paint1.setAntiAlias(true);
        paint1.setShader(radialGradient1);
        canvas.drawCircle(1920,0,1100,paint1);

        RadialGradient radialGradient2 = new RadialGradient(1920,1080,1100,colors2,null, Shader.TileMode.CLAMP);
        Paint paint2 = new Paint();
        paint2.setAntiAlias(true);
        paint2.setShader(radialGradient2);
        canvas.drawCircle(1920,1080,1100,paint2);



        RadialGradient radialGradient3 = new RadialGradient(0,1080,1100,colors3,null, Shader.TileMode.CLAMP);
        Paint paint3 = new Paint();
        paint3.setAntiAlias(true);
        paint3.setShader(radialGradient3);
        canvas.drawCircle(0,1080,1100,paint3);


//        RadialGradient radialGradient4 = new RadialGradient(0,0,1100,colors4,null, Shader.TileMode.CLAMP);
//        Paint paint4 = new Paint();
//        paint4.setAntiAlias(true);
//        paint4.setShader(radialGradient4);
//        canvas.drawCircle(0,0,1100,paint4);


    }
}
